package cn.edu.scau.cmi.chenzehan.client;
import cn.edu.scau.cmi.chenzehan.singlepattern.Dean;
import cn.edu.scau.cmi.chenzehan.singlepattern.HeadMaster;
import cn.edu.scau.cmi.chenzehan.singlepattern.President;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class UisinglePattern extends Application {

	@Override
	public void start(Stage primaryStage) {
		GridPane pane = new GridPane();
		
		pane.setHgap(100);
		pane.setVgap(100);
		ImageView prisident_view = new ImageView("cn/edu/scau/cmi/chenzehan/singlepattern/毛爷爷.jpg");
		prisident_view.setFitHeight(200);
		prisident_view.setFitWidth(200);
		
		ImageView dean_view = new ImageView("cn/edu/scau/cmi/chenzehan/singlepattern/院长.jpg");
		dean_view.setFitHeight(200);
		dean_view.setFitWidth(200);
		
		ImageView headmaster_view = new ImageView("cn/edu/scau/cmi/chenzehan/singlepattern/校长.png");
		headmaster_view.setFitHeight(200);
		headmaster_view.setFitWidth(200);
		
		Button bt1 = new Button("选举主席");
		Button bt2 = new Button("选举院长");
		Button bt3 = new Button("选举校长");
		Button bt4 = new Button("重选主席");
		Button bt5 = new Button("重选院长");
		Button bt6 = new Button("重选校长"); 
		
		pane.add(prisident_view,0,0);
		pane.add(dean_view,1,0);
		pane.add(headmaster_view,2,0);
		
		HBox hbox = new HBox();
		hbox.getChildren().addAll(bt1,bt2,bt3);
		hbox.setMargin(bt1,new Insets(50,50,50,50));
		hbox.setMargin(bt2,new Insets(50,50,50,170));
		hbox.setMargin(bt3,new Insets(50,50,50,170));
		
		
		
		HBox hbox2 = new HBox();
		hbox2.getChildren().addAll(bt4,bt5,bt6);
		hbox2.setMargin(bt4,new Insets(50,50,50,50));
		hbox2.setMargin(bt5,new Insets(50,50,50,170));
		hbox2.setMargin(bt6,new Insets(50,50,50,170));
		BorderPane pane2 = new BorderPane();
		pane2.setTop(hbox);
		pane2.setCenter(hbox2);
		BorderPane borderPane = new BorderPane();
		borderPane.setTop(pane);
		borderPane.setCenter(pane2);
		
		bt1.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent event) {
				if(President.addPresident("毛泽东")){
					System.out.println("选举成功，毛泽东成为主席");
				}
				else System.out.println("选举新主席失败，主席已经当选");
			     
			}
		});
		bt2.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent event) {
				if(Dean.addDean("��")){
					System.out.println("选举成功，刘成为院长");
				}
				else System.out.println("选举新院长失败，刘已经当选");
				
			}
		});
		bt3.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent event) {
				if(HeadMaster.addHeadMaster("miss刘")){
					System.out.println("选举成功，miss刘成为校长");
				}
				else System.out.println("选举新校长长失败，miss刘已经当选");
			}
		});
		bt4.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent event) {
				if(!President.addPresident("毛泽东")) {
					President.setPresidentEmpty();
					System.out.println("准备重选，主席任期已满");
				}
			}
		});
		bt5.setOnAction(e->{
			if(!Dean.addDean("刘")) {
				Dean.setDeanEmpty();;
				System.out.println("准备重选，院长任期已满");
			}
		});
		bt6.setOnAction(e->{
			if(!HeadMaster.addHeadMaster("miss刘")) {
				HeadMaster.setHeadMasterEmpty();
				System.out.println("准备重选，校长任期已满");
			}
		});
		
		Scene scene = new Scene(borderPane,900,600);
		primaryStage.setTitle("单例模式ʽ");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	
	public static void main(String[] args) {
		Application.launch(args);
	}

}
